﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using BackEnd.Common;
using BackEnd.Models;
using BusinessLayer.FindArtInfo;
using BusinessLayer.RegInfo;
using BusinessLayer.RegInfo.Entities;
using BusinessLayer.RegInfo.Models;
using Constants = CommandLib.Constants;

namespace BackEnd.Controllers
{
    public class TransactionLogController : Controller
    {
        //
        // GET: /TransactionLog/

        public JsonResult Search(string email, int? subscriptionId, int? typePay, int? status, int? partnerId, DateTime? fromDate, DateTime? toDate, int? typeTransaction, int pageIndex, int pageSize)
        {
            int totalRecord;
            List<TransactionLogExtend> listTransactionLog = new TransactionLogBL().Search(email, subscriptionId, typePay, status, partnerId, fromDate, toDate, typeTransaction, pageIndex, pageSize, out totalRecord);
            ListObjectModel<TransactionLogExtend> listObject = new ListObjectModel<TransactionLogExtend>
            {
                ListItem = listTransactionLog,
                PageIndex = pageIndex,
                PageSize = pageSize,
                TotalRecord = totalRecord
            };
            return Json(listObject, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetAllTransactionLogByAccountId(int accountId, int pageIndex, int pageSize)
        {
            int totalRecord;
            List<TransactionLogExtend> listTransactionLog = new TransactionLogBL().GetAllTransactionLogByAccountId(accountId, pageIndex, pageSize, out totalRecord);
            ListObjectModel<TransactionLogExtend> listObject = new ListObjectModel<TransactionLogExtend>
            {
                ListItem = listTransactionLog,
                PageIndex = pageIndex,
                PageSize = pageSize,
                TotalRecord = totalRecord
            };
            return Json(listObject, JsonRequestBehavior.AllowGet);
        }        

        [HttpPost]
        [CustomAuthorize(Action = Common.Constants.AdminActions.DeleteTransactionLog)]
        public JsonResult Delete(string listId)
        {
            TransactionLogBL transactionLogBL= new TransactionLogBL();
            string[] arrayId = listId.Split('_');
            for (int i = 0; i < arrayId.Length; i++)
            {
                transactionLogBL.Delete(Convert.ToInt64(arrayId[i]));
            }
            return Json("Success", JsonRequestBehavior.AllowGet);
        }

    }
}
